/**
 * 
 */

$(document).ready(function() {
	var _submiting1 = false;

	$('#myForm').validator({
		rules : {},
		fields : {
			'#brandName' : 'required',
			'#brandId' : 'required'
		},
		valid : function(form) {
			if (_submiting1) {

				return;
			}
			_submiting1 = true;

			FormSubmit(form, function(response) {
				if(response.data > 0){
					_showInfoMessage("保存成功。", 'success'); 
					$('#showNewsModal').modal('hide');
					
				} else if(response.data == -1){
					_showInfoMessage("品牌ID不能重复。", 'error'); 
				}
				_submiting1 = false;
			});
		}
	});

	$('#btnSave').click(function() {

		$('#myForm').submit();
		return false;

	});
});
options.openDialog = function(mpId) {
	var _modal = $('#showNewsModal');
	_modal.modal('show');
	_modal.find('#mpId').val(mpId);

	$.ajax({
		url : 'getCrmBrandInfo',
		type : 'post',
		data : {
			mpId : mpId
		},
		success : function(response) {
			var brandName = '';
			var brandId = '';
			var zhugeAppKey = '';
			if (response.data != null) {
				brandName = response.data.brandName;
				brandId = response.data.brandId;
				zhugeAppKey = response.data.zhugeAppKey;
			}
			_modal.find('#brandName').val(brandName);
			_modal.find('#brandId').val(brandId);
			_modal.find('#zhugeAppKey').val(zhugeAppKey);
		},
		error : function(result) {
			_showInfoMessage("操作失败。", 'error');
		}
	});
}